package exam.xiecheng.spring.S3;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();
        System.out.println(solution(s, n, k));
    }

    public static int solution(String s, int n, int k) {
        int left = 0, right = 0, maxLen = 0, distinct = 0;
        int[] window = new int[26];
        while (right < n) {
            char c = s.charAt(right++);
            if (window[c-'a'] == 0) {
                distinct++;
            }
            window[c-'a']++;
            if (distinct <= k)
                maxLen = Math.max(maxLen, right-left);
            while (distinct > k) {
                char d = s.charAt(left++);
                window[d-'a']--;
                if (window[d-'a']==0)
                    distinct--;
            }
        }
        return maxLen;
    }
}